﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Core;

namespace JV.Com.Tools
{
    public static class DispatcherHelper
    {
        public static void Init(CoreDispatcher dispatcher)
        {
            s_instance = dispatcher;
        }

        private static CoreDispatcher s_instance;
        public static CoreDispatcher Instance { get { return s_instance; } }

        public static async Task RunInUIThreadAsync(Action action)
        {
            if (s_instance.HasThreadAccess) action();
            else await s_instance.RunAsync(CoreDispatcherPriority.Normal, () => action());
        }
    }
}
